var AddPerson = {};
AddPerson.contextpath = "";
AddPerson.initPage = function(contextpath) {
	AddPerson.contextpath = contextpath;

	layui.use(['form', 'layedit', 'laydate','upload'], function(){
		  var form = layui.form
		  ,layer = layui.layer
		  ,upload = layui.upload;
		 
		  //自定义验证规则
		  form.verify({
			  userName: function(value){
		      layedit.sync(editIndex);
		    }
		  });
		  
		  //监听提交
		  form.on('submit(submit)', function(data){
			  AddPerson.ajaxSaveUser(data);
		    return false;
		  });
			upload.render({
				elem : '#myfile',
				url : '/web2019/blinddate/uploadPicture.action',
				accept : 'file' //普通文件
				,
				size: 6000,
				exts : 'jpg|png|gif|bmp|jpeg' //允许上传的文件后缀
				,
				done : function(res) {//返回值接收
					if (res.code == "0000") {
						layer.msg('导入成功！', {}, function() {
//							location.reload();
							$("#picId").val(res.picId);
							$("#picUrl").attr("src",res.picUrl);
						});
					} else {
						layer.msg('导入失败！', {}, function() {
//							location.reload();
						});
					}
				}
			});
		});
	

}


AddPerson.ajaxSaveUser = function(data1) {
	$.ajax({
		type : "POST",
		url : "/web2019/blinddate/ajaxSavePerson.action",
		dataType : "json",
		data : data1.field,
		beforeSend:function(){
			layer.load(1);
		},
		complete:function(){
			layer.close(layer.index-1);
		},
		success : function(data) {
			if (data.code == "0000") {
				layer.alert(data.message, { icon: 1, closeBtn: 0 }, function (index) { 
					layer.close(index);
					window.location.href="/web2019/blinddate/addPerson.action";
				});
			} else {
				layer.alert(data.message);
			}
		},
		error : function(data) {

		}
	});
}
